//
//  SLUserInfoModel.m
//  globalTranslate
//
//  Created by 陈镇 on 2025/8/12.
//

#import "SLUserInfoModel.h"
#import "CZKeyChainHandle.h"


static SLUserInfoModel *_manager = nil;
@implementation SLUserInfoModel


+(instancetype)shareManage{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _manager = [SLUserInfoModel createUserInfo];
    });
    return _manager;
}



-(NSString *)head{
    if (!_head) {
        NSInteger index = random()%9 + 1;
        _head = [NSString stringWithFormat:@"my_user_hear_0%@",@(index)];
    }
    return _head;
}

-(NSString *)userName{
    if (!_userName) {
        NSInteger time = [NSDate new].timeIntervalSince1970;
        time =  (time + random()%10000 ) %1000000;
        _userName = [NSString stringWithFormat:@"用户%@",@(time)];
    }
    return _userName;
}



+(instancetype)createUserInfo{
    
    
   NSString *sting = [CZKeyChainHandle czValueforKey:@"SLUserInfoModel"];
    
    if (!sting) {
        
        SLUserInfoModel *model = [[SLUserInfoModel alloc] init];
        [model head];
        [model userName];
        [CZKeyChainHandle cz_setValue:model.yy_modelToJSONString forKey:@"SLUserInfoModel"];
    }
    SLUserInfoModel *mode = [SLUserInfoModel yy_modelWithJSON:sting];
    
    return mode;;
    
}

-(void)saveUserInfo{
    
    
    [CZKeyChainHandle cz_setValue:self.yy_modelToJSONString forKey:@"SLUserInfoModel"];
    
}
@end
